﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Draw_Task
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            g.Clear(Color.White);
            Pen myPen = new Pen(Color.Blue, 3);
            Point oo1 = new Point(30, this.ClientSize.Height - 100);
            Point oo2 = new Point(this.ClientSize.Width - 50, this.ClientSize.Height - 100);
            g.DrawLine(myPen, oo1, oo2);
            Point oo3 = new Point(30, 30);
            g.DrawLine(myPen, oo1, oo3);
            Font f = new Font("宋体", 12, FontStyle.Bold);
            g.DrawString("x", f, myPen.Brush, oo2);
            g.DrawString("y", f, myPen.Brush, 10, 10);

            float x1 = 0, x2 = 0;
            double y1 = 0;
            double y2 = this.ClientSize.Height - 100;
            for (x2 = 0; x2 < this.ClientSize.Width; x2++)
            {
                double a = 2 * Math.PI * x2 / (this.ClientSize.Width);
                y2 = Math.Sin(a);
                y2 = (1 - y2) * (this.ClientSize.Height - 100) / 2;
                g.DrawLine(myPen, x1 + 30, (float)y1, x2 + 30, (float)y2);
                x1 = x2;
                y1 = y2;
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Pen p = new Pen(Color.Blue);
            Graphics g = this.CreateGraphics();
            g.Clear(Color.White);
            Rectangle r = new Rectangle(50, 50, 200, 100);
            Brush b = new SolidBrush(Color.Blue);
            g.FillPie(p.Brush, r, 0, 60);
            g.FillPie(b, r, 60, 150);
            b = new SolidBrush(Color.Yellow);
            g.FillPie(b, r, 210, 150);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Graphics g = Graphics.FromImage(pictureBox1.Image);
            Font f = new Font("隶书", 80, FontStyle.Italic);
            Pen p = new Pen(Color.OrangeRed);
            g.DrawString("花开花落", f, p.Brush, 0, 0);
            p.Dispose();
            g.Dispose();
            pictureBox1.Refresh();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            pictureBox1.Image.Save("C:/User");
        }
    }
}
